package com.alianzamedica.controllers;

import java.io.File;
import java.util.Iterator;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.objectsearch.sqlsearch.ObjectSearch;
import org.w3c.dom.Document;
import com.alianzamedica.businessobject.Doctor;

/**
 * @author Carlos
 * 
 */
public class Testing {

	/**
	 * asa.
	 * 
	 * @return asa.
	 * @throws Exception
	 *             asa.
	 */
	public Document getDocument() throws Exception {
		File file = new File(
				"C:\\workspaces\\alianzamedica\\AlianzaMedica\\WebContent\\WEB-INF\\settings\\objectmapping.xml");
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		DocumentBuilder builder = factory.newDocumentBuilder();
		Document doc = builder.parse(file);
		return doc;
	}

	/**
	 * asa.
	 * 
	 * @throws Exception
	 *             asa.
	 */
	@SuppressWarnings("unchecked")
	public void searchDoctor() throws Exception {
		Doctor d = new Doctor();
		d.setEmail("carlos@ingeniagroup.com");
		d.setPassword("123456");
		ObjectSearch search = new ObjectSearch(getDocument(),
				"com.alianzamedica.connection.ConnectionTest");
		search.setDefaultDialect(ObjectSearch.MYSQL_DIALECT);
		Iterator<Doctor> iterator = search.searchObjects(d).iterator();
		while (iterator.hasNext()) {
			Doctor doctor = (Doctor) iterator.next();
			System.out.println("id:" + doctor.getId());
			System.out.println("nombre: " + doctor.getFirstName());
		}
	}

	/**
	 * asa.
	 * 
	 * @param args
	 *            asa.
	 */
	public static void main(String[] args) {
		Testing testing = new Testing();
		try {
			testing.searchDoctor();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
